/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Vue;

import java.awt.AlphaComposite;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.Shape;
import java.awt.font.FontRenderContext;
import java.awt.font.GlyphVector;
import java.awt.geom.Rectangle2D;
import java.io.File;
import javax.swing.JLabel;

/**
 *
 * @author Gloire
 */
@SuppressWarnings("serial")
public class LabelLettre extends JLabel{
    
    private int x;
    private int y;
    private int hauteur;
    private int color = 0;
    private char c;
    private JLabel pts;
    private int points;
    
    
    public LabelLettre(int x, int y, int h, char c,int valeur){
        super((c+"").toUpperCase());
        points = valeur;
        pts = new JLabel(points+"");
        try{
        setFont(Font.createFont(Font.TRUETYPE_FONT,
					new File("./src/images/font.ttf")).deriveFont(
					Font.BOLD, 40f));
        
        pts.setFont(Font.createFont(Font.TRUETYPE_FONT,
					new File("./src/images/font.ttf")).deriveFont(
					Font.BOLD, 15f));
        }catch(Exception e){
            System.out.println("j'ai pas trouvé le fichier de caractere");
        }
        this.x = x;
        this.y = y;
        this.hauteur= h;
        this.c = c;
        
    }
    
    @Override
    public void paint(Graphics arg){
        Graphics2D g = (Graphics2D) arg;
        BasicStroke bs = new BasicStroke(5);
        g.setStroke(bs);
        Rectangle2D rect = new Rectangle2D.Double(x, y,hauteur , hauteur);
        g.setColor(Color.LIGHT_GRAY);
        g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,0.1f));
        g.fill(rect);
        g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,0.5f));
        if(color == 1)
            g.setColor(Color.ORANGE);
        if(color == 2)
            g.setColor(Color.CYAN);
        if(color == -1)
            g.setColor(Color.RED);
        g.draw(rect);
        
        FontRenderContext frc = g.getFontRenderContext();
        GlyphVector gv = getFont().createGlyphVector(frc, getText());
        Rectangle2D box = gv.getVisualBounds();

        int xOff = (int) -box.getX()+x+40;
        int yOff = (int) -box.getY()+y+40;

        Shape shape = gv.getOutline(xOff, yOff);

        g.setClip(null);
        g.setColor(Color.WHITE);
        g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,0.9f));

        g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                           RenderingHints.VALUE_ANTIALIAS_ON);
        g.fill(shape);
        
        gv = pts.getFont().createGlyphVector(frc, pts.getText());
        box = gv.getVisualBounds();

        xOff = (int) -box.getX()+x+5;
        yOff = (int) -box.getY()+y+3;

        shape = gv.getOutline(xOff, yOff);

        g.setClip(null);
        g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,0.9f));
        g.fill(shape);
        
    }
    
    public void setColor(int n){
        this.color = n;
    }
    
}
